import { createRouter, createWebHashHistory } from 'vue-router'
export const routes = [
  {
    path: '/firsthome',
    name: 'firsthome',
    label: '前端首页',
    component: () => import('@/views/HomeView.vue'),
    children: [
      {
        label: '轮播图/产品展示',
        path: 'manager',
        name: 'manager',
        component: () => import('@/views/manager/ManagerIndexView.vue')
      },
      {
        label: '商品页面',
        path: 'commodity',
        name: 'commodity',
        component: () => import('@/views/commodity/CommodityIndexView.vue'),
        children: [
          {
            label: '商品分类',
            path: 'bannerlist',
            name: 'bannerlist',
            component: () => import('@/views/banner/BannerListView.vue'),
            children: [
              {
                label: '商品详情页',
                path: 'banneradd',
                name: 'banneradd',
                component: () => import('@/views/banner/BannerAddView.vue')
              }
            ]
          }
        ]
      },
      {
        label: '订单页面',
        path: 'orders',
        name: 'orders',
        component: () => import('@/views/orders/OrdersIndexView.vue'),
        children: [
          {
            label: '购物车页面',
            path: 'productionlist',
            name: 'productionlist',
            component: () => import('@/views/production/ProductionListView.vue')
          }
        ]
      },
      {
        label: '个人中心',
        path: 'my',
        name: 'my',
        component: () => import('@/views/my/MyIndexView.vue'),
        children: [
          {
            label: '个人信息',
            path: 'mymessage',
            name: 'mymessage',
            component: () => import('../views/center/myMessage.vue')
          },
          {
            label: '我的订单',
            path: 'myorder',
            name: 'myorder',
            component: () => import('../views/center/myOrder.vue')
          },
          {
            label: '收货地址',
            path: 'myaddress',
            name: 'myaddress',
            component: () => import('../views/center/myAddress.vue')
          }
        ]
      }
    ]
  },
  {
    path: '/lasthome',
    name: 'lasthome',
    label: '后台首页',
    component: () => import('@/views/HomeLastView.vue'),
    children: [
      {
        label: '用户管理',
        path: 'manager',
        name: 'manager',
        component: () => import('@/views/manager/ManagerIndexView.vue'),
        children: [
          {
            label: '权限管理',
            path: 'managerlist',
            name: 'managerlist',
            component: () => import('@/views/manager/ManagerListView.vue')
          }
        ]
      },
      {
        label: '商品列表',
        path: 'banner',
        name: 'banner',
        component: () => import('@/views/banner/BannerIndexView.vue'),
        children: [
          {
            label: '商品增删改',
            path: 'bannerlist',
            name: 'bannerlist',
            component: () => import('@/views/banner/BannerListView.vue')
          }
        ]
      },
      {
        label: '轮播图',
        path: 'production',
        name: 'production',
        component: () => import('@/views/production/ProductionIndexView.vue'),
        children: [
          {
            label: '轮播图增删改',
            path: 'productionlist',
            name: 'productionlist',
            component: () => import('@/views/production/ProductionListView.vue')
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    label: '登录',
    name: 'login',
    component: () => import('@/views/LoginView.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// //需要前置路由守卫进行登录拦截
// const isLogin = () => {
//   return localStorage.getItem('token') ? true : false
// }
// router.beforeEach((to) => {
//   if (to.name === 'login') {
//     if (isLogin()) {
//       ElMessage('登录有效')
//       return {
//         name: 'home'
//       }
//     }
//   } else if (to.name === 'home') {
//     // 访问首页的时候如果没有登录，就跳转到登录页面
//     if (!isLogin()) {
//       return { name: 'login' }
//     }
//   }
// })
export default router
